﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LGPSDataGen
{
    public class DateUtility
    {
        //Get the int value of month's
        public static int ConvertMonthToInt(string month)
        {
            string lower = month.ToLower();
            int returnCode = 0;
            {
                if (lower.Contains("january") || lower.Contains("jan"))
                    returnCode = 1;
                else if (lower.Contains("february") || lower.Contains("feb"))
                    returnCode = 2;
                else if (lower.Contains("march") || lower.Contains("mar"))
                    returnCode = 3;
                else if (lower.Contains("april") || lower.Contains("apr"))
                    returnCode = 4;
                else if (lower.Contains("may"))
                    returnCode = 5;
                else if (lower.Contains("june") || lower.Contains("jun"))
                    returnCode = 6;
                else if (lower.Contains("july") || lower.Contains("jul"))
                    returnCode = 7;
                else if (lower.Contains("august") || lower.Contains("aug"))
                    returnCode = 8;
                else if (lower.Contains("september") || lower.Contains("sep"))
                    returnCode = 9;
                else if (lower.Contains("october") || lower.Contains("oct"))
                    returnCode = 10;
                else if (lower.Contains("november") || lower.Contains("nov"))
                    returnCode = 11;
                else if (lower.Contains("december") || lower.Contains("dec"))
                    returnCode = 12;
                else
                    returnCode = 0;
            }

            return returnCode;
        }

        //Determine if a string has a month in it
        public static bool IsMonthString(string valueToEvaluate)
        {
            bool returnCode = false;
            string lower = valueToEvaluate.ToLower();
            if(lower.Contains("january") || lower.Contains("jan"))
                returnCode = true;
            else if (lower.Contains("february") || lower.Contains("feb"))
                returnCode = true;
            else if (lower.Contains("march") || lower.Contains("mar"))
                returnCode = true;
            else if (lower.Contains("april") || lower.Contains("apr"))
                returnCode = true;
            else if (lower.Contains("may"))
                returnCode = true;
            else if (lower.Contains("june") || lower.Contains("jun"))
                returnCode = true;
            else if (lower.Contains("july") || lower.Contains("jul"))
                returnCode = true;
            else if (lower.Contains("august") || lower.Contains("aug"))
                returnCode = true;
            else if (lower.Contains("september") || lower.Contains("sep"))
                returnCode = true;
            else if (lower.Contains("october") || lower.Contains("oct"))
                returnCode = true;
            else if (lower.Contains("november") || lower.Contains("nov"))
                returnCode = true;
            else if (lower.Contains("december") || lower.Contains("dec"))
                returnCode = true;
            else
                returnCode = false;
 
            return returnCode;
        }

        //Add 12 to PM values, 0 to AM values
        public static int AMorPM(string eval)
        {
            if (eval.Contains("AM"))
                return 0;
            else
                return 12;
        }

        //Convert the physical day to a double
        public static double DayToInt(DateTime d)
        {
            if (d.DayOfWeek == DayOfWeek.Sunday)
                return 0 / 7.0;
            else if (d.DayOfWeek == DayOfWeek.Monday)
                return 1 / 7.0;
            else if (d.DayOfWeek == DayOfWeek.Tuesday)
                return 2 / 7.0;
            else if (d.DayOfWeek == DayOfWeek.Wednesday)
                return 3 / 7.0 ;
            else if (d.DayOfWeek == DayOfWeek.Thursday)
                return 4 / 7.0;
            else if (d.DayOfWeek == DayOfWeek.Friday)
                return 5 / 7.0;
            else 
                return 6 / 7.0;
        }

        //Is the date a weekend
        public static int WeekEndFlag(DateTime d)
        {
            if (d.DayOfWeek == DayOfWeek.Saturday || d.DayOfWeek == DayOfWeek.Sunday)
                return 1;
            else 
                return 0;
        }

        //Is the date a holiday
        public static int IsHoliday(DateTime d)
        {
            if (d.Month == 1 && d.Day == 1) //new years
                return 1;
            else if (d.Month == 5 && d.Day == 30) //memorial day
                return 1;
            else if (d.Month == 7 && d.Day == 4) //july 4th 
                return 1;
            else if (d.Month == 9 && d.Day == 5) //labor day
                return 1;
            else if (d.Month == 10 && d.Day == 10) //columbus day
                return 1;
            else if (d.Month == 11 && d.Day == 11) //veterans day
                return 1;
            else if (d.Month == 11 && d.Day == 24) //turkey day
                return 1;
            else if (d.Month == 12 && d.Day == 25) //xmas
                return 1;
            else if (d.Month == 12 && d.Day == 31) //new years
                return 1;
            else
                return 0;
        }
    }
}
